package com.example.demo.config;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * @program: demo
 * @author: JCM
 * @create: 2023-04-25 17:49
 * @description:
 **/
@ControllerAdvice
public class ExConfigurer {
    @ExceptionHandler(NullPointerException.class)
    @ResponseBody
    public Object handler(NullPointerException e) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("state",0);
        map.put("data",null);
        map.put("msg","异常："+e.getMessage());
        return map;
    }
}
